package edu.luc.concordia;

import java.util.ArrayList;

/**
 * Copyright 2008 Project Concordia
 * <p>
 * This file is part of RetailReturnSystem.
 * <p>
 * RetailReturnSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * <hr>
 * Adds items to myInventory and stores as a temporary receipt.
 * @author Paul Zolnierczyk
 * @version 0.3 2008-10-07
 */

public class PurchaseRecorder 
{
	private Inventory myInventory;
	private ArrayList<Product> myScannedItems = new ArrayList<Product>();
	
	/*
	 * Class Constructor
	 */
	public PurchaseRecorder(Inventory inven)
	{
		myInventory = inven; 
	}
	
	/**
	 * Scans an item into myScannedItems after verification product exists
	 * and product quantity greater than integer zero.
	 * @param uid - a String unique identification number that comes from the scanner GUI.
	 * @param quantity - an integer specifying the amount of the product to be added to myScannedItems.
	 * @return scannedProductDesc - returns the description of the item scanned to the Scanner GUI.
	 */
	public Product scanItem(String uid, int quantity)
	{
		Product myProduct = myInventory.getProduct(uid);
		
		if (myProduct != null && quantity > 0)
		{			
			for(int i = 0; i < quantity; ++i)
			{
				myScannedItems.add(myProduct);
			}
			return myProduct;			
		}
		return null;		
	}
	/** 
	 * @return myScannedItems - an ArrayList of myScannedItems added by the scanItem method.
	 */
	public ArrayList<Product> getScannedItems()
	{
			//Comment by Paul for Robbie, what does returning a clone object do again?
			return (ArrayList<Product>) myScannedItems.clone();
	}

}
